<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  
  <title>Introduction &middot; jQuery Masonry</title>
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
  
  <link rel="stylesheet" href="../css/style.css" />
  
  
  <!-- scripts at bottom of page -->

</head>
<body class="docs ">
  
  <nav id="site-nav">
    <h1><a href="../index.html">jQuery Masonry</a></h1>
    
    <h2>Docs</h2>
    
    <ul class="docs-list">
      
        
        <li class="current"><a href="#content">Introduction</a>
          <ul class="toc">
            
            <li><a href="#getting_started">Getting started</a></li>
            
            <li><a href="#code_repository">Code repository</a></li>
            
            <li><a href="#acknowledgments">Acknowledgments</a></li>
            
            <li><a href="#changelog">Changelog</a></li>
            
            <li><a href="#license">License</a></li>
            
          </ul>
        </li>
        
      
        
          
            <li><a href="../docs/options.html">Options</a>
          
        
      
        
          
            <li><a href="../docs/methods.html">Methods</a>
          
        
      
        
          
            <li><a href="../docs/animating.html">Animating</a>
          
        
      
        
          
            <li><a href="../docs/help.html">Help</a>
          
        
      
    </ul>

    <h2>Demos</h2>
    
    <ul class="demos-list">
      
        
          
            <li><a href="../demos/basic-single-column.html">Basic single-column</a>
          
        
      
        
          
            <li><a href="../demos/basic-multi-column.html">Basic multi-column</a>
          
        
      
        
          
            <li><a href="../demos/images.html">Images</a>
          
        
      
        
          
            <li><a href="../demos/tumblelog.html">Tumblelog example</a>
          
        
      
        
          
            <li><a href="../demos/animating-jquery.html">Animating with jQuery</a>
          
        
      
        
          
            <li><a href="../demos/animating-css-transitions.html">Animating with CSS Transitions</a>
          
        
      
        
          
            <li><a href="../demos/animating-modernizr.html">Animating with Modernizr</a>
          
        
      
        
          
            <li><a href="../demos/adding-items.html">Adding items</a>
          
        
      
        
          
            <li><a href="../demos/infinite-scroll.html">Infinite Scroll</a>
          
        
      
        
          
            <li><a href="../demos/gutters.html">Gutters</a>
          
        
      
        
          
            <li><a href="../demos/right-to-left.html">Right-to-left</a>
          
        
      
        
          
            <li><a href="../demos/centered.html">Centered</a>
          
        
      
        
          
            <li><a href="../demos/fluid.html">Fluid</a>
          
        
      
        
          
            <li><a href="../demos/corner-stamp.html">Corner stamp</a>
          
        
      
    </ul>
    
  </nav> <!-- #site-nav -->
  
  <section id="content">
    
    
      <h1>Introduction</h1>
    
    
    <p>Masonry is a dynamic grid layout plugin for jQuery. Think of it as the flip-side of CSS floats. Whereas floating arranges elements horizontally then vertically, Masonry arranges elements vertically, positioning each element in the next open spot in the grid. The result minimizes vertical gaps between elements of varying height, just like a mason fitting stones in a wall.</p>

<h2 id='getting_started'>Getting started</h2>

<h3 id='markup'>Markup</h3>

<p>Masonry works on a container element with a group of similar child items.</p>
<div class='highlight'><pre><code class='html'><span class='nt'>&lt;div</span> <span class='na'>id=</span><span class='s'>&quot;container&quot;</span><span class='nt'>&gt;</span>
  <span class='nt'>&lt;div</span> <span class='na'>class=</span><span class='s'>&quot;item&quot;</span><span class='nt'>&gt;</span>...<span class='nt'>&lt;/div&gt;</span>
  <span class='nt'>&lt;div</span> <span class='na'>class=</span><span class='s'>&quot;item&quot;</span><span class='nt'>&gt;</span>...<span class='nt'>&lt;/div&gt;</span>
  <span class='nt'>&lt;div</span> <span class='na'>class=</span><span class='s'>&quot;item&quot;</span><span class='nt'>&gt;</span>...<span class='nt'>&lt;/div&gt;</span>
  ...
<span class='nt'>&lt;/div&gt;</span>
</code></pre>
</div>
<p>Add jQuery and the Masonry script. Masonry requires jQuery v1.4.0 and greater.</p>
<div class='highlight'><pre><code class='html'><span class='nt'>&lt;script </span><span class='na'>src=</span><span class='s'>&quot;//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js&quot;</span><span class='nt'>&gt;&lt;/script&gt;</span>
<span class='nt'>&lt;script </span><span class='na'>src=</span><span class='s'>&quot;/path/to/jquery.masonry.min.js&quot;</span><span class='nt'>&gt;&lt;/script&gt;</span>
</code></pre>
</div>
<h3 id='css'>CSS</h3>

<p>All sizing of items is handled by your CSS. Items should be floated.</p>
<div class='highlight'><pre><code class='css'><span class='nc'>.item</span> <span class='p'>{</span>
  <span class='k'>width</span><span class='o'>:</span> <span class='m'>220px</span><span class='p'>;</span>
  <span class='k'>margin</span><span class='o'>:</span> <span class='m'>10px</span><span class='p'>;</span>
  <span class='k'>float</span><span class='o'>:</span> <span class='k'>left</span><span class='p'>;</span>
<span class='p'>}</span>
</code></pre>
</div>
<h3 id='script'>Script</h3>

<p>It is recommended you specify an <code>itemSelector</code> and <code>columnWidth</code>. There are a number of other <a href='options.html'>options</a> you can specify.</p>
<div class='highlight'><pre><code class='javascript'><span class='nx'>$</span><span class='p'>(</span><span class='kd'>function</span><span class='p'>(){</span>
  <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;#container&#39;</span><span class='p'>).</span><span class='nx'>masonry</span><span class='p'>({</span>
    <span class='c1'>// options</span>
    <span class='nx'>itemSelector</span> <span class='o'>:</span> <span class='s1'>&#39;.item&#39;</span><span class='p'>,</span>
    <span class='nx'>columnWidth</span> <span class='o'>:</span> <span class='mi'>240</span>
  <span class='p'>});</span>
<span class='p'>});</span>
</code></pre>
</div>
<p>That&#8217;s it!</p>

<p><a href='../demos/basic-multi-column.html'><strong>See Demo: Basic multi-column</strong></a></p>

<h3 id='imagesloaded_plugin'>imagesLoaded plugin</h3>

<p>If your content contains any images, you&#8217;ll want to ensure that Masonry is triggered after all the images your content has loaded. The included <a href='https://github.com/desandro/imagesloaded'>imagesLoaded plugin</a> makes this easy.</p>
<div class='highlight'><pre><code class='javascript'><span class='kd'>var</span> <span class='nx'>$container</span> <span class='o'>=</span> <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;#container&#39;</span><span class='p'>);</span>
<span class='nx'>$container</span><span class='p'>.</span><span class='nx'>imagesLoaded</span><span class='p'>(</span><span class='kd'>function</span><span class='p'>(){</span>
  <span class='nx'>$container</span><span class='p'>.</span><span class='nx'>masonry</span><span class='p'>({</span>
    <span class='nx'>itemSelector</span> <span class='o'>:</span> <span class='s1'>&#39;.item&#39;</span><span class='p'>,</span>
    <span class='nx'>columnWidth</span> <span class='o'>:</span> <span class='mi'>240</span>
  <span class='p'>});</span>
<span class='p'>});</span>
</code></pre>
</div>
<p><a href='../demos/images.html'>See Demo: Images</a></p>

<h2 id='code_repository'>Code repository</h2>

<p>This project lives on GitHub at <a href='http://github.com/desandro/masonry'>github.com/desandro/masonry</a>. There you can grab the latest code and follow development.</p>

<h2 id='acknowledgments'>Acknowledgments</h2>

<ul>
<li>Louis-Rémi Babé and Paul Irish for the <a href='http://github.com/louisremi/jquery-smartresize'>jQuery SmartResize plugin</a>. De-bounced window resize event handler. Used within Masonry.</li>

<li>Paul Irish and Luke Shumard for <a href='http://www.infinite-scroll.com'>Infinite Scroll</a>. Pretty much Masony&#8217;s BFF &#60;3.</li>

<li>The Modernizr team for <a href='http://www.modernizr.com/'>Modernizr</a>. Used in most of these demos.</li>

<li>Paul Irish et. al. for <a href='https://gist.github.com/268257'>imagesLoaded plugin</a>. Used within Masonry.</li>

<li><a href='http://twitter.com/ralphholzmann'>Ralph Holzmann</a> for re-writing the <a href='http://docs.jquery.com/Plugins/Authoring'>jQuery Plugins/Authoring tutorial</a> and opened my eyes to <a href='http://docs.jquery.com/Plugins/Authoring#Plugin_Methods'>Plugin Methods</a> pattern.</li>

<li><a href='http://www.erichynds.com/'>Eric Hynds</a> for his article <a href='http://www.erichynds.com/jquery/using-jquery-ui-widget-factory-bridge/'>Using $.widget.bridge Outside of the Widget Factory</a> which provided the architecture for Masonry.</li>
</ul>

<h2 id='changelog'>Changelog</h2>
<dl>
  <dt>v2.1: 9 Dec 2011</dt>
    <dd>Pass in a function for <code>columnWidth</code> for easier fluid layouts</dd>
  <dt>v2.0: May 2011</dt>
    <dd>Complete re-write. Uses <code>$.Mason</code> constructor, like jQuery UI widget</dd>
    <dd>Add options <code>gutterWidth</code>, <code>isFitWidth</code> for centering layout, <code>isRTL</code> for right-to-left layout</dd>
    <dd>Add all new methods like <code>appended</code>, and <code>reload</code></dd>
    <dd>Remove filtering demos</dd>
  <dt>v1.3: 3 Sep 2010</dt>
    <dd>Revamped <code>appendedContent</code> to work with container elements.  Plays nice with latest Infinite Scroll.</dd>
    <dd>Revised layout for documentation to allow for more pages.</dd>
  <dt>v1.2: 12 Jun 2010</dt>
    <dd>Support for filtering added</dd>
  <dt>v1.1: 29 Apr 2010</dt>
    <dd>Add animation</dd>
  <dt>v1.0: 7 Dec 2009</dt>
    <dd>Multi-column width support</dd>
  <dd>Appending elements and Infinite Scroll support</dd>
    <dd>Less obstrusive layout. No inserting additional markup.</dd>
    <dd>Automatically binds event to window resizing</dd>
  <dt>v0.4: 14 Jun 2009</dt>
    <dd>Better fluid rearrangement support</dd>
  <dt>v0.1: Feb 2009</dt>
    <dd>Original release</dd>
</dl>
<h2 id='license'>License</h2>

<p>jQuery Masonry is licensed under the MIT license. It may be used for personal and commercial applications.</p>
<div class='license-copy'>
  <h3>The MIT License</h3>
  <p>Copyright &copy; 2011 David DeSandro</p>
  <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
  <p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
  <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</div>
    
    <footer id="site-footer">
      jQuery Masonry by <a href="http://desandro.com">David DeSandro</a>
    </footer>
    
  </section> <!-- #content -->

</body>
</html>